//
//  BaseViewController.swift
//  Weibo2
//
//  Created by 伏文东 on 2018/2/6.
//  Copyright © 2018年 伏文东. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
    
    var cisitorDictionaryInfo: [String: String]?
    
    var tableView: UITableView?
    var refreshControl: UIRefreshControl?
    var isPullup = false
    
    lazy var navigationBar = SecondNavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.screenWidth(), height: 64))
    lazy var navItem = UINavigationItem()

    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    override var title: String? {
        didSet {
            navItem.title = title
        }
        
    }
    
    // MARK: - 监听方法
    @objc func loadData() {
        refreshControl?.endRefreshing()
    }
    
}

extension BaseViewController {
    @objc func setupUI()  {
        
        setupNavigationBar()
        setupTableView()
    }
    
    func setupNavigationBar()  {
        view.addSubview(navigationBar)
        
        navigationBar.items = [navItem]
        
        navigationBar.barTintColor = UIColor.colorWithHex(hex: 0xf6f6f6)
        navigationBar.tintColor = UIColor.orange
        
        navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.darkGray]
    }
    func setupTableView()  {
        tableView = UITableView(frame: view.bounds, style: .plain)
        view.insertSubview(tableView!, belowSubview: navigationBar)
        
        tableView?.delegate = self
        tableView?.dataSource = self
        tableView?.contentInset.top = 44
        tableView?.scrollIndicatorInsets.top = 44
        
        refreshControl = UIRefreshControl()
        tableView?.addSubview(refreshControl!)
        
        refreshControl?.addTarget(self, action: #selector(loadData), for: .valueChanged)
    }
}

extension BaseViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        return UITableViewCell()
    }
}




























